<?php
	if(!defined("IN_APP"))
	{
		exit;
	}
	
	if(!adminpermission('Y','Y100001'))
	{
		echo '无权查看!';
		exit;
	}
	
	$method = getParam('m','get','list');
	
	$parm = requestArrayParm($_REQUEST);
	
	
	if($method == 'detail')
	{
		if(!empty($parm['id']))
		{
			//获取用户
			$info = _User::getUserInfo(array('id'=>$parm['id']));
			if($info)
			{
				$info['oplist'] = _OpLog::getOpLogListByWhere(array('table'=>'users','union_id'=>$info['id']));
				

				unset($wheres);
				$wheres['uid'] = $info['id'];
				$info['accountlist'] = _Account_number::getAccount_numberList($wheres);
			
				include renderTemplate('admin/user/user');
			}
			else
			{
				header("Location:".SITE_URL.'admin.php?a=userM');
				exit;
			}
		}
		else
		{
			header("Location:".SITE_URL.'admin.php?a=userM');
			exit;
		}
	}
	
	if($method == 'userfanli')
	{
		if(!empty($parm['uid']))
		{
			//获取用户
			$info = _User::getUserInfo(array('id'=>$parm['uid']));
				
			unset($where);
			$where['uid'] = $parm['uid'];
			$where['status'] = '2';
			$sort['addtime'] = 'desc';
			$resData = _Fanli::getFanliList($where, array(), array(), $sort);
			foreach ($resData as $key => $value)
			{
				//获取产品信息
				$value['chanpin'] = _ChanPin::getChanPinInfo(array('id'=>$value['pid']));
				//获取获取项目信息
				$value['item'] = _ChanPin::getChanPin_ItemInfo(array('id'=>$value['iid']));
				
				$value['opinfo'] = _OpLog::getLastOpLog(array('table'=>'fanli','union_id'=>$value['id']));
				
				$list[] = $value;
			}
		
			include renderTemplate('admin/user/userfanli');
		}
		else
		{
			header("Location:".SITE_URL.'admin.php?a=userM');
			exit;
		}
	}
	
	if($method == 'usertixian')
	{
		if(!empty($parm['uid']))
		{
			//获取用户
			$info = _User::getUserInfo(array('id'=>$parm['uid']));
			
			unset($where);
			$where['uid'] = $parm['uid'];
			$where['status'] = '2';
			$sort['addtime'] = 'desc';
			$resData = _Tixian::getTixianList($where, array(), array(), $sort);
			foreach ($resData as $key => $value)
			{
				$value['opinfo'] = _OpLog::getLastOpLog(array('table'=>'tixian','union_id'=>$value['id']));
				
				$list[] = $value;
			}
			include renderTemplate('admin/user/usertixian');
		}
		else
		{
			header("Location:".SITE_URL.'admin.php?a=userM');
			exit;
		}
	}
	
	if($method == 'list')
	{
		$typearr['name'] = '姓名';
		$typearr['phone'] = '手机号';
		
		$fTitle = "用户管理";
		$sTitle = "用户列表";
		
		$search = array();
		
		if($parm['start'] && $parm['end'])
		{
			$between['start'] = strtotime($parm['start']);
			
			$between['end'] = strtotime($parm['end']);
		}
		
		if($parm['type'] == 'name')
		{
			$search['nickname'] = $parm['keyword'];
		}
		
		if($parm['type'] == 'phone')
		{
			$search['loginname'] = $parm['keyword'];
		}

		
		if($parm['status'])
		{
			$search['status'] = $parm['status'];
		}
		
		$page = $pages['page'] = getParam('page','request','1');
		
		$pages['rows'] = 20;
		
		$resData = _User::getUserList($search,$pages,$between);
		
		//查询对应的数据
		
		foreach ($resData['list']  as $key => $value)
		{
			$value['data'] = _User::getUsertouziData($value['id']);
			
			$value['data2'] = _User::getUsertixianData($value['id']);
			
			$list[] = $value;
		}
		
		$pageurl = SITE_URL.'admin.php?'.set_URL_Param(get_URL_Param());
	
		$pagetotal = $resData["pages"];
		
		include renderTemplate('admin/user/userlist');
	}
	
	